<template>
	<view class="mainpadding" v-if="pageShow">
		<view class="flexbetween margin_top">
			<view class="" style="width: 47%;">
				<view class="flexleft fenrun1">
					<image src="../../static/image/system/left.png" mode=""></image>
					<view class="titletext bold" style="color: #FF8F43;">当月分润</view>
				</view>
				<view class="itemcontent" @click="jumpurl('/pages/index/fenrunjl?type=0')">
					<view class="xiaohui strongtext">金额(元)</view>
					<view class="margin_top2 xiaohei titletext bold" style="font-size: 40rpx;">{{userInfo?userInfo.lastmouth_frprice : 0}}</view>
				</view>
			</view>
			<view class="" style="width: 47%;">
				<view class="flexleft fenrun2">
					<image src="../../static/image/system/right.png" mode=""></image>
					<view class="titletext bold" style="color: #3B50FF;">累计分润</view>
				</view>
				<view class="itemcontent" @click="jumpurl('/pages/index/fenrunjl?type=1')">
					<view class="xiaohui strongtext">金额(元)</view>
					<view class="margin_top2 xiaohei titletext bold" style="font-size: 40rpx;">{{userInfo?userInfo.total_frprice : 0}}</view>
				</view>
			</view>
		</view>
		<u-tabs :list="list1" lineColor="#3B50FF" @click="changetab" :current="currentindex"
			:activeStyle="{
			    color: '#000000',
			    fontWeight: 'bold',
			    transform: 'scale(1.05)'
			}" :inactiveStyle="{
			            color: '#666666',
						fontWeight: '500',
			            transform: 'scale(1)'
			        }" itemStyle="height: 44px;"></u-tabs>
		<view class="ffffff mainpadding_top radius" v-for="item in list.data" :key="item.id">
			<view class="flexbetween">
				<view class="sanshier xiaohei">{{item.memo}}</view>
				<view class="xiaolan bold titletext">{{item.money}}</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="xiaohui strongtext">{{item.createtime}}</view>
			</view>
		</view>
		<view class="textcenter margin_top xiaohui" v-if="tabsid==1" @click="year=year-1;init(true)">点击加载更多</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				list1: [{
						name: '当月',
						value: 0,
					},
					{
						name: '累计',
						value: 1,
					}
				],
				currentindex:0,
				tabsid:0,
				userInfo:null,
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				pageShow:false,
				// 日期参数
				year:"",
			}
		},
		onLoad(option) {
			this.tabsid = option.type
			this.currentindex = option.type
			this.year = new Date().getFullYear()
			this.getuser()
			this.init()
		},
		methods: {
			retrundate(val){
				let now = new Date();
				let year = now.getFullYear();
				let month = now.getMonth() + 1;
				let day = now.getDate();
				if(val==1){//今日
					return year + "-"+ (month>9?month:'0'+month) + "-"+ (day>9?day:'0'+day)
				}else{
					return year + "-"+ (month>9?month:'0'+month) + "-01"
				}
			},
			init(isPage, page) {
				let _this = this
				httpRequest.request('/api/user/mouthPosFr', 'GET', {
					date: this.tabsid==1?this.year:"",
					ly:this.tabsid==1?2:1,
				}).then(res => {
					if (res.code == 1) {
						// let resList = res.data;
						// let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = _this.list.data.concat(res.data);
						} else {
							_this.list.data = res.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			// init(isPage, page) {
			// 	let _this = this
			// 	httpRequest.request('/api/user/moneyLog', 'GET', {
			// 		page: page || 1,
			// 		limit: _this.limit,
			// 		type: 2,
			// 		start_time:this.tabsid?"": this.retrundate(2),
			// 		end_time: this.tabsid?"": this.retrundate(1)
			// 	}).then(res => {
			// 		if (res.code == 1) {
			// 			let resList = res.data;
			// 			let dataList = _this.list;
			// 			if (isPage == true) {
			// 				_this.list.data = dataList.data.concat(resList.data);
			// 			} else {
			// 				this.list = res.data
			// 				_this.list.data = resList.data;
			// 			}
			// 		}
			// 	}).catch(err => {
			// 		httpRequest.toast(err.msg);
			// 	})
			// },
			// onReachBottom() {
			// 	let _this = this;
			// 	let list = _this.list;
			// 	let page = _this.page;
			// 	if (list.last_page <= page) {
			// 		return false;
			// 	}
			// 	page++;
			// 	_this.page = page;
			// 	_this.init(true, page);
			// },
			getuser() {
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					if (res.code == 1) {
						this.userInfo = res.data
						this.pageShow = true
					} else {
						this.userInfo = null
					}
			
				})
			},
			changetab(e) {
				this.tabsid = e.value
				this.currentindex = e.index
				this.year = new Date().getFullYear()
				this.init()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.fenrun1{
		border-radius: 20rpx;
		background: linear-gradient( 270deg, #FFDBC1 0%, #FFEEE4 100%);
		padding: 20rpx 20rpx 50rpx;
		box-sizing: border-box;
		image{
			width: 45rpx;
			height: 45rpx;
			margin-right: 20rpx;
		}
	}
	.fenrun2{
		border-radius: 20rpx;
		background-color: #e6e8fa;
		padding: 20rpx 20rpx 50rpx;
		box-sizing: border-box;
		image{
			width: 45rpx;
			height: 45rpx;
			margin-right: 20rpx;
		}
	}
.itemcontent {
		position: relative;
		top: -30rpx;
		background-color: #fff;
		width: 100%;
		border-radius: 20rpx;
		padding: 30rpx 20rpx;
		box-sizing: border-box;
	}
</style>
